package com.mmy.service.car.impl;

import java.util.List;
import java.util.Map;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import com.alibaba.fastjson.JSONObject;
import com.mmy.dao.car.TCarBaseRepository;
import com.mmy.dao.car.VCarBaseRepository;
import com.mmy.domain.car.TCarBase;
import com.mmy.domain.car.VCarBase;
import com.mmy.mapper.CarDao;
import com.mmy.service.car.TCarBaseService;

@Service
public class TCarBaseServiceImpl implements TCarBaseService {

	@Autowired
	TCarBaseRepository tCarBaseRepository;
	@Autowired
	VCarBaseRepository vCarBaseRepository;
	@Autowired
	CarDao carDao;
	
	/**
	  * @descr 租车级联选择器 
	  * @param 
	  * @return 
	  * @throws 
	  * @author liys
	  * @date 2021-6-28
	 */
	public String carSelect() {
		
		List<Map<String,Object>> list = carDao.getCarTypes();
		for (Map<String, Object> item : list) {
			item.put("children", carDao.getCarsByType((int) item.get("value")));
		}
		return JSONObject.toJSONString(list);
	} 
	
	/**
	 * 查找全部
	 * 
	 * @param
	 * @return
	 */
	public List<VCarBase> findAll() {
		// TODO Auto-generated method stub
		return vCarBaseRepository.findAll();
	}

	/**
	 * 获得最大编号
	 * 
	 * @return 返回值说明 最大ID
	 * @author 创建人 dingxd
	 * @date 创建日期 2020.11.17
	 */
	public int getMaxCarID() {
		// 流水号
		Object objCode = tCarBaseRepository.getMaxCarID();
		int iID = 0;
		if (objCode != null) {
			iID = Integer.parseInt(objCode.toString());
		}
		return iID;
	}

	/**
	 * 新增
	 * 
	 * @param
	 * @return
	 */
	public void save(TCarBase tCarBase) {
		// TODO Auto-generated method stub
		tCarBaseRepository.save(tCarBase);
	}

	/**
	 * 删除
	 * 
	 * @param
	 * @return
	 */
	public void delCarBase(List<Integer> lstCarID) {
		// TODO Auto-generated method stub
		tCarBaseRepository.delCarBase(lstCarID);
	}

	/**
	 * 通过id查找
	 * 
	 * @param
	 * @return
	 */
	public TCarBase findByCarID(int iCarID) {
		// TODO Auto-generated method stub
		return tCarBaseRepository.findByCarID(iCarID);
	}



	/**
	 * 新增id
	 * 
	 * @param
	 * @return
	 */
	public void save(int carID) {
		// TODO Auto-generated method stub
		tCarBaseRepository.save(carID);
	}

	/**
	 * 通过name查找
	 * 
	 * @param
	 * @return
	 */
	public List<VCarBase> findByName(String strTypeName, String strOrgName) {

		return vCarBaseRepository.findByName(strTypeName, strOrgName);
	}

	/**
	 * 通过id查找
	 * 
	 * @param
	 * @return
	 */
	public VCarBase findByID(int iCarID) {
		// TODO Auto-generated method stub
		return vCarBaseRepository.findByCarID(iCarID);
	}
}
